home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT1-5 / MACLIB.INC < prev    next >
Encoding:
Text File  |  1994-08-27  |  4.7 KB  |  190 lines

  1. .XLIST
  2. ;       M A C R O   D E F I N I T I O N
  3. ;       ═══════════════════════════════
  4. ;
  5. ;       Program MacLib.INC ( Chapter 5 )_
  6. ;
  7. InpInt  macro   Dest
  8.     local   Read , ExitMac , Number
  9. ;       if      <Dest> ne 'ax'
  10. ;               push    ax
  11. ;       endif
  12.     push    cx
  13.     push    bx
  14.     mov     bx,0
  15.     mov     cx,0
  16. ;       push    dx
  17.     mov     Dest,0
  18. Read:
  19.     mov     ah,1            ; Prepare Dos Service Call - function 1
  20.     int     21h             ; Dos Service 01 - get symbol with echo
  21.     mov     dl,al           ; Save symbol to proceeding
  22. ;
  23. ;       Check if symbol is a number 0 ... 9
  24. ;
  25.     cmp     al,'0'          ; Compare symbol in AL and ASCII code "0"
  26.     jl      ExitMac         ; If symbol is less than "0" it is no number
  27.     cmp     al,'9'          ; Compare symbol in AL and ASCII code "9"
  28.     jg      ExitMac         ; If symbol is greater than "9" it is no number
  29.                 ;===  Leave macro
  30. Number:                         ;
  31.     mov     ah,0
  32.     sub     al,'0'          ; Convert symbol in AL into number
  33.     mov     cx,ax           ; Save this number into CL
  34.     mov     ax,10           ; Prepare to computing result
  35. ;       mul     bl              ; AL = BL * 10
  36. ;       add     al,cl           ; AL = ( BL * 10 )+ AL
  37.     mul     bx              ; AX = BX * 10
  38.     add     ax,cx           ; AX = ( BX * 10 )+ AX
  39.     mov     bx,ax           ; Save the current result
  40.                 ;
  41.     jmp     Read            ; Read next symbol
  42.  
  43. ExitMac:
  44.     mov     ax,bx           ; Save result into AX register
  45.     pop     bx              ; Restore BX ( work register )
  46.     pop     cx              ; Restore CX ( work register )
  47. ;       if      <Dest> ne 'ax'
  48.         mov     Dest,ax ; Put result into target
  49. ;               pop     ax      ; Restore AX register
  50. ;       endif
  51.     endm
  52.                 ;
  53. OutInt  macro   Src
  54.     local   NexDiv,OutSym
  55.     push    ax
  56.     push    bx
  57.     push    cx
  58.     push    dx
  59.     mov     ax,Src          ; Place number to be printed into AX.
  60. ;       mov     ah,0
  61.     mov     bx,10           ; Place number '10'(divider) into DI.
  62.     mov     cx,0
  63. NexDiv:
  64.     mov     dx,0
  65.     div     bx              ; Divide command. After this result is in
  66.                 ;    AL register and remainder in AH.
  67.     push    dx              ; Push Remainder into stack.
  68. ;       mov     ah,0            ; Clear High byte of number to be divided.
  69.     inc     cx              ; Increase counter
  70.     cmp     ax,0            ; Check if result is zero and
  71.     jne     NexDiv
  72.     mov     ax,200h
  73. OutSym: pop     dx
  74.     add     dl,'0'
  75.     int     21h
  76.     loop    OutSym
  77.     pop     dx
  78.     pop     cx
  79.     pop     bx
  80.     pop     ax
  81.     endm
  82. OutStr  macro   tpar
  83.     local   locpar,aftcon   ; These label are internal
  84. ;;
  85. ;;      Attention! That's really wonderful!
  86. ;;      If you replace the name "locpar" with the
  87. ;;      name "par", MASM 5.0 will put the message
  88. ;;      "Error between phases".
  89. ;;
  90.     push    ds              ; Save
  91.     push    dx              ;      the
  92.     push    ax              ;          registers
  93. ;
  94. ;       This locates parameter text in memory
  95. ;
  96.     ifndef  tpar            ; Check wether parameter
  97.                 ;   is present
  98.     jmp     aftcon          ; Avoid to execute constants
  99. locpar  db      tpar            ; Text string into memory
  100.     db      0Dh, 0Ah        ; Line feed, carriage return
  101.     db      '$'             ; This is needed for DOS
  102. aftcon:
  103.     endif
  104.     mov     dx,cs
  105.     mov     ds,dx
  106.     mov     dx,offset cs:locpar
  107. ;
  108.     mov     ah,9            ; Service 09 - put string
  109.     int     21h             ; Dos service call
  110.     pop     ax              ; Restore
  111.     pop     dx              ;         the
  112.     pop     ds              ;             registers
  113.     endm
  114. NewLine macro   Num
  115.     push    ax
  116.     push    dx
  117.     mov     ah,02h
  118.     mov     dx,0Dh          ; Output CR
  119.     int     21H
  120.     mov     dx,0Ah          ; Output LF
  121.     int     21h
  122.     pop     dx
  123.     pop     ax
  124.     endm
  125. UpCase  macro   Letter
  126.     local   UpCase,NotLet
  127.     cmp     Letter,'a'
  128.     jl      NotLet
  129.     cmp     Letter,'z'
  130.     jg      NotLet
  131. UpCase: and     al,0DFh                 ; Force upper case
  132. NotLet:
  133.     endm
  134. ToFlags macro   prm
  135.     push    prm
  136.     popf
  137.     endm
  138. GetFlags macro  prm
  139.     pushf
  140.     pop     prm
  141.     endm
  142.  
  143. OutMsg  macro   txt
  144.     local   MsgTxt,Work
  145.     jmp     Work
  146. MsgTxt  db      txt,'$'
  147. Work:   push    ax
  148.     push    dx
  149.     push    ds
  150.     push    cs
  151.     pop     ds
  152.     mov     dx,offset cs:MsgTxt
  153.     mov     ah,09
  154.     int     21h
  155.     pop     ds
  156.     pop     dx
  157.     pop     ax
  158.     endm
  159.  
  160. OutChar macro   CharForOutput
  161.     push    ax
  162.     push    dx
  163.     mov     ah,02
  164.     mov     dl,CharForOutput
  165.     int     21h
  166.     pop     dx
  167.     pop     ax
  168.     endm
  169.     
  170. OutBytes        macro   TextArr,LArray
  171.     local   OutNext
  172.     push    ax
  173.     push    bx
  174.     push    cx
  175.     push    dx
  176.     mov     bx,0
  177.     mov     cx,LArray
  178.     mov     ah,02
  179. OutNext:mov     dl,TextArr[bx]
  180.     int     21h
  181.     inc     bx
  182.     loop    OutNext 
  183.     pop     dx
  184.     pop     cx
  185.     pop     bx
  186.     pop     ax
  187.     endm
  188. .List
  189. .sall
  190.